/*
 * Lexer.h
 *
 *  Created on: 15.09.2012
 *      Author: steiner
 */

#ifndef LEXER_H_
#define LEXER_H_

#include <iostream>
#include <map>
#include <vector>
#include <deque>

using namespace std;

namespace IO {

typedef struct {
	int column;
	int row;
} Position;

/**
 * Class
 * @description The base class of the Lexers
 */
template<typename T> class Lexer {
public:
	/**
	 * Constructor
	 * @param basic_istream Stream from which should be read.
	 */
	Lexer(basic_istream<T> *, map<vector<T>, int> *);

	/**
	 * Destructor
	 */
	virtual ~Lexer();

	/**
	 * Method
	 * @return bool Returns true if the stream end has reached.
	 * @description Reads the next Token from the stream.
	 */
	virtual bool next();

	vector<T> getToken() const;

	int getTokenIndex() const;

protected:
	basic_istream<T> *in;
	map<vector<T>, int> *tokenTable;
	pair<vector<T>, int> *currentToken;
	pair<vector<T>, int> *nextToken;
	Position currentPosition;
	deque<T> *buffer;
	bool readFromBuffer;

	T readNextChar();

	inline bool isNewline(T);

	inline bool isWhitespace(T);

private:
	map<vector<T>, int> *getPossibleTokenMatches(map<vector<T>, int> *, int, T);

};

} /* namespace IO */
#endif /* LEXER_H_ */
